// JavaScript Document
//运行
$(function(){
	
var leftPage = {  
    Models: {},  
	Views: {},  
	Controllers: {},  
	Collections: {},  
	initialize: function() {  
		new App.Controllers.Routes();  
		Backbone.history.start();
	}  
};

//商品
leftPage.Models.Nav = Backbone.Model.extend({
	
});

leftPage.Views.Nav = Backbone.View.extend({
		el:$()
});

//我喜欢的
leftPage.Models.Likeitem = Backbone.Model.extend({
	defaults:
		{
        	"title":"美女哪个美",
            "href":"http://www.baidu.com",
            "id":10,
			"price":200,
            "img":"images/tu2.jpg",
            "user":{
            	"name":"用户名",
                "img":"images/tu.gif",
                "href":"http://www.taobao.com"
            }
        }
});
leftPage.Collections.Likeitem = Backbone.Collection.extend({
	model:leftPage.Models.Likeitem
});

leftPage.Views.Likeitem = Backbone.View.extend({
		tagName:"li",
		render:function(){
			this.tmpl = this.tmpl || _.template($("#J_Tmpl_like_item").html());
			$(this.el).html(this.tmpl(this.model.toJSON()));
		},
		initialize:function(){
			this.model.view = this;
			this.render();
		},
		dosome:function(){
			var c = $(this.el).find(".J_dosome");
			$(this.el).height($(this.el).height());
			$(this.el).css({overflow:"hidden"});
			$(this.el).append(c.clone(false));
			
			c.animate({marginTop:-c.height()},500,function(){
				c.remove();
			});
		}
});


leftPage.Models.Like = Backbone.Model.extend({
	defaults:{
		"name":"我朋友喜欢的"
	}
});

leftPage.Views.Like = Backbone.View.extend({
		ul:[],
		render:function(){
			this.tmpl = this.tmpl || _.template($("#J_Tmpl_like_area").html());
			$(this.el).html(this.tmpl(this.model.toJSON()));
		},
		addOne:function(li){
			var view = new leftPage.Views.Likeitem({model:li})
			this.ul.push(view);
			$(this.el).find("ul").append(view.el);
		},
		events : {
			"click .likes a":"dosome"
		},
		dosome:function(e){
			_.each(this.ul,function(d){
				d.dosome();
			});
			return false;
		}
});


	var	bb = new leftPage.Views.Like({model:new leftPage.Models.Like,el:$("#J_Like_friend")});
		bb.render();
		bb.addOne(new leftPage.Models.Likeitem());
		bb.addOne(new leftPage.Models.Likeitem());
		bb.addOne(new leftPage.Models.Likeitem());
});



$(function(){
	$("#J_Class").delegate("a","click",function(){
		$("#J_Class").find(".class_nav").hide();
		$("#J_Class").find(".static_height").show();
	});
	
	$("#J_Like_huan").each(function(e){
		var $this = $(this),c_do=false;
		$this.find(".likes:eq(0)").find("a:eq(0)").on("click",function(){
			if(c_do){
				return false;
			}
			c_do=true;
			var list = $this.find(".likes_list"),
				ul = list.find("ul:eq(0)"),
				ul_height = ul.height();
				list.height(ul_height).css("overflow","hidden");
				list.append(ul.clone());
				list.stop().animate({scrollTop:ul_height},ul_height*2,function(){ ul.remove();list.scrollTop(0);c_do=false; });
				return false;
		});
	});
	
	$("#J_Sbgg1_btn").click(function(){
		var self = this;
		$(self).parents("ul").find("li.selected").removeClass("selected");
					$(self).parents("li").addClass("selected");
		var $nav = $("#J_Nav"),
			$nav_warp = $nav.find(".nav_warp"),
			sbgg = $("#J_Tmpl_sbgg1").html();
			$nav_warp.append(sbgg);
			$nav.stop().animate({scrollLeft:225},
				function(){
					
				});
	});
	
	$("#J_Sbgg_btn").click(function(){
		$("#J_Sbgg_btn").parents("ul").find("li.selected").removeClass("selected");
					$("#J_Sbgg_btn").parents("li").addClass("selected");
		var $nav = $("#J_Nav"),
			$nav_warp = $nav.find(".nav_warp"),
			sbgg = $("#J_Tmpl_sbgg").html();
			$nav_warp.append(sbgg);
			$nav.stop().animate({scrollLeft:450},
				function(){
					
				});
	});
	
	$("#J_Index_btn").click(function(){
		$("#J_Index_btn").parents("ul").find("li.selected").removeClass("selected");
					$("#J_Index_btn").parents("li").addClass("selected");
		var $nav = $("#J_Nav");
			$nav.stop().animate({scrollLeft:0},
				function(){
					
				});
	});
});